package com.yanqu.road.server.cmd.beauty;

import com.yanqu.road.entity.player.UserBeauty;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.pb.BeautyPb;
import com.yanqu.road.pb.beauty.BeautyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = BeautyProto.BeautyUpgradeSkillReqMsg.class, respMsg = BeautyProto.BeautyUpgradeSkillRespMsg.class)
@Cmd(code = Protocol.S_BEAUTY_UPGRADE_SKILL, desc = "美女升级门客技能")
public class BeautySkillUpgradeCmd extends AbstractCommand {

	private int beautyId;

	private int type;//对应技能

	private int position;

	private int batch;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		BeautyProto.BeautyUpgradeSkillReqMsg reqMsg = BeautyProto.BeautyUpgradeSkillReqMsg.parseFrom(packet.getBytes());
		beautyId = reqMsg.getBeautyId();
		type = reqMsg.getType();
		position = reqMsg.getPosition();
		if(reqMsg.hasBatch()) {
			batch = reqMsg.getBatch();
		}else {
			batch = 1;
		}
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
	    if(batch != 1 && batch != 10){
	        ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
	        return;
        }
		ret = player.getModule(BeautyModule.class).beautyUpgradeSkill(beautyId, type, position, batch);
	}

	@Override
	public void sendData(GamePlayer player) {
		BeautyProto.BeautyUpgradeSkillRespMsg.Builder respMsg = BeautyProto.BeautyUpgradeSkillRespMsg.newBuilder();
		respMsg.setRet(ret);
		if(0 == ret){
			UserBeauty userBeauty = player.getModule(BeautyModule.class).getUserBeauty(beautyId);
			BeautyProto.BeautyTempMsg.Builder beautyMsg = BeautyPb.parseBeautyTempMsg(userBeauty);
			if(null != beautyMsg){
				respMsg.setBeauty(beautyMsg);
			}
		}
		player.sendPacket(Protocol.U_BEAUTY_UPGRADE_SKILL, respMsg);
	}
}
